#论文的main代码
import cv2
import custom
import numpy as np
pic=cv2.imread("pic/", 0)
custom.showPicture("original",pic)
laplian_pic=custom.laplian(pic,3)
# print(laplian_pic[]) #可查看每一层的数值 0 1 2 三层
xgm=[]
for i in range(3):
    xgm.append(custom.fuzzySets(laplian_pic[i]))

down1=cv2.pyrDown(pic);
down2=cv2.pyrDown(cv2.pyrDown(pic));
down3=cv2.pyrDown(cv2.pyrDown(cv2.pyrDown(pic)));


pic_1=0.6*xgm[0]*down1      #图像通过阈值和a 加权 a1=0.1 a2=0.3 a3=0.6
pic_2=0.3*xgm[1]*down2
pic_3=0.1*xgm[2]*down3
# custom.showPicture("0",pic_1)             #输出图像，每一层加权后的图像
# custom.showPicture("1",pic_2)
# custom.showPicture("2",pic_3)
# cv2.waitKey(0)
# print("图1大小：",pic_1.shape,"\n图2大小：",pic_2.shape,"\n图3大小：",pic_3.shape)#输出图片大小

pic_2_up=cv2.pyrUp(pic_2)   #第二层向上采样一次
pic_2_up=custom.shapePicture(pic_2_up,pic_1)#判断两个图像是否一样大

pic_3_up=cv2.pyrUp(pic_3)   #第三层向上采样两次
pic_3_up=custom.shapePicture(pic_3_up,pic_2)
pic_3_up=cv2.pyrUp(pic_3_up)
pic_3_up=custom.shapePicture(pic_3_up,pic_1)#判断两个图像是否一样大
# print("图1大小：",pic_1.shape,"\n图2大小：",pic_2_up.shape,"\n图3大小：",pic_3_up.shape)#输出图片大小

pic_total=((pic_1+pic_2_up+pic_3_up)*4).astype(np.uint8)#改变图像存储类型取整
custom.showPicture("total1",pic_total)

# pic_total=cv2.pyrUp(pic_total) #多添加一个细节像素低的不行
# picX=cv2.Laplacian(pic,-1)
# pic_total=custom.shapePicture(pic_total,picX)
# pic_total=pic_total+picX

pic_total = cv2.bilateralFilter(pic_total, 5, 30, 30)#双边滤波函数
# pic_total=cv2.equalizeHist(pic_total)#直方图均衡化

custom.showPicture("total",pic_total)
cv2.waitKey(0)


